$(function () {
    $.validator.addMethod("checkName", function (val) {
        return /^[a-z]\w+/i.test(val);
    })

    $("form").validate({
        rules: {
            // unickname: {
            //     required: true
            // },
            uname: {
                required: true,
                checkName: true,
                rangelength: [6, 18],
                remote: "./account/checkname"
            },
            upwd: {
                required: true,
                rangelength: [6, 18]
            },
            upwd2: {
                equalTo: "#upwd"
            },
            uphone: {
                digits: true,
                rangelength: [11, 11]
            }
        },
        messages: {
            // unickname: {
            //     required: "昵称必填"
            // },
            uname: {
                required: "用户名必填",
                checkName: "字母开头",
                rangelength: "用户名长度必须{0}-{1}",
                remote: "该用户名已经注册"
            },
            upwd: {
                required: "密码必填",
                rangelength: "密码长度必须{0}-{1}"
            },
            upwd2: {
                equalTo: "2次密码不一致"
            },
            uphone: {
                digits: "只能数字",
                rangelength: "手机号必须11位"
            }
        },
        submitHandler() {

            $.ajax({
                url: "./account/reg",
                type: "post",
                data: $("form").serialize() //前端发送到服务器的数据 data
            }).then(function (response) { //服务器响应到前端的数据 response
                //    layer.open()
                // layer.msg()
                // layer.msg("注册成功");
                if (response.status == 200) {
                    layer.msg("注册成功");
                    setTimeout(() => {
                        location = "login.html";
                    }, 2000);
                } else {
                    layer.msg("注册失败")
                }

                // layer.confirm("提示的问题", {
                //     btn: ["确定", "取消"]
                // },function (index) {
                //     //默认是不会关闭窗口

                //     // layer.clsoe(index) ,点完确定之后,才会关闭窗口

                // },function () {

                // })


            })

            return false;
        }
    })

})

$(function () {
    $('.regbox>form p input').on('focus', function () {
        $(this).css('border', '1px solid lightblue')
    }).on('blur', function () {
        $(this).css('border', '1px solid #ccc')
    })
})